from typing import Optional, List


class Solution:
    # def twoSum(self, nums: List[int], target: int) -> List[int]:
    #     for i in range(len(nums)):
    #         for j in range(i+1, len(nums)):
    #             if nums[i] + nums[j] == target:
    #                 return [i, j]
    # def twoSum(self, nums: List[int], target: int) -> List[int]:
    #     for i in range(len(nums)):
    #         res = target - nums[i]
    #         if res in nums[i + 1:]:
    #             return [i, nums[i + 1:].index(res)+i+1]
    # 使用哈希表的方法
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        dp = {}
        for index, value in enumerate(nums):
            res = target - value
            if res in dp:
                return [dp[res], index]
            else:
                dp[value] = index


so = Solution()
print(so.twoSum([3, 3], 6))
